<?php
	$errorMsg = '';
	$errorClass = 'errorMsg';
	if( Login::$loginStatus == Login::USER_LOGGED_IN ) {
		header( 'Location: /' . Login::getUserInfo( 'login' ) . '/' );
		exit;
	}

	$postVars = isset( Url::$pageVars[ 'GETPOST' ] ) ? Url::$pageVars[ 'GETPOST' ] : array();
	if( isset( $postVars[ 'login' ] ) && isset( $postVars[ 'password' ] ) ) {
		try {
			$login = $postVars[ 'login' ];
			$result = Login::login( $login, $postVars[ 'password' ] );
			if( $result == 1 ){
				$profileurl = 'http://' . $login . '.' . HOST_NAME;
				header( 'Location: ' . $profileurl );
				exit;	
			}elseif( $result == -1 ){
				$errorMsg = 'Incorrect login/password !';
			}elseif( $result == -4 ){
				$errorMsg = 'You are Banned !';
			}else{
				$errorMsg = 'You are not authorized to login !';
			}			
		} catch( Exception $ex ) {
			// describe( $ex, true );
			$errorMsg = $ex->getMessage();
		}
	}
	$template->message = $errorMsg;
	$template->msgClass = $errorClass;

$template->welcomeMsg = "Login Form";